package com.sf.dlb.web.controller;


import com.sf.dlb.service.BaseUserWalletService;
import com.sf.dlb.web.service.UserWarningService;
import com.sf.dlb.utils.DateUtils;

import com.sf.dlb.utils.ResultVOUtil;
import com.sf.dlb.web.config.Global;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;


/**
 * 系统设置相关
 * Created by jing.tan on 2018/12/10.
 */
@RestController
@RequestMapping(value = "/v1/admin")
public class AdminController {
    private static Logger logger = LoggerFactory.getLogger(AdminController.class);
    @Resource
    private Global global;
    @Resource
    private BaseUserWalletService userWalletService;
    @Autowired
    private UserWarningService warningService;
    /**
     * 手动触发解锁
     *
     * @returns
     */
    @GetMapping(value = "/checkUnlock/{day}")
    @ResponseBody
    public Object checkUnlock(@PathVariable String day) {
        logger.info("checkUnlock start time = "+ DateUtils.getDateTime()+" "+global);
        userWalletService.checkUnlockDlb(Integer.parseInt(day));
        logger.info("checkUnlock start end = "+ DateUtils.getDateTime());
        return ResultVOUtil.success();
    }
    /**
     * 手动触发定时任务
     *
     * @returns
     */
    @GetMapping(value = "/handlerScheduledTask/{day}")
    @ResponseBody
    public Object handlerScheduledTask(@PathVariable String day) {
        logger.info("handlerScheduledTask start time = "+ DateUtils.getDateTime());
        String date=DateUtils.addTimeByDay(new Date(),Integer.parseInt(day));
        warningService.warning(date);
        logger.info("handlerScheduledTask start end = "+ DateUtils.getDateTime());
        return ResultVOUtil.success();
    }
    /**
     * 监控url
     *
     * @returns
     */
    @GetMapping(value = "/monitorUrl")
    @ResponseBody
    public Object monitorUrl() {
        logger.info("monitorUrl start time = "+ DateUtils.getDateTime()+" ");
        return ResultVOUtil.success();
    }
}
